package com.lnu.information.exception;

import java.util.Scanner;

/**
 * @author : jian.zhang-2
 * @description:
 * @date : Create in 2:56 PM 2022/4/28
 * @modified By :
 */
class MyException extends Exception {
    String message;

    public MyException(String message) {
        this.message = message;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
public class ExceptionDemo{
    static int quotient(int x, int y) throws MyException {
        if(y<0){
            throw new MyException("除数不能是负数");
        }else if(y == 0){
            throw new MyException("除数不能是0");
        }
        return x/y;
    }

    public static void main(String[] args) {
        int m,n;
        System.out.println("Input two number for m,n");
        Scanner scanner = new Scanner(System.in);
        m=scanner.nextInt();
        n=scanner.nextInt();
        try {
            int result = quotient(m, n);
            System.out.println(m + "/" + n + "=" + result);
        }catch (MyException e){
            System.out.println(e.getMessage());
        }catch (Exception e){
            System.out.println("程序发生了其他异常");
        }finally {
            scanner.close();
        }
    }
}

